<!DOCTYPE html>
<html>

	<head lang="en">
		<title>首页</title>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
		<link rel="stylesheet" href="/js/bootstrap-4.1.1-dist/css/bootstrap.min.css">
		<script src="/js/jquery/jquery.min.js"></script>
		<script src="/js/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
		<link rel="stylesheet" href="/css/font/css/font-awesome.min.css" />
		<link rel="stylesheet" href="/css/reset.css" />
        <link rel="stylesheet" type="text/css" href="fonts/font-awesome-4.5.0/css/font-awesome.min.css" />
        <link rel="stylesheet" type="text/css" href="css/demo.css">
        <link rel="stylesheet" type="text/css" href="css/icons.css" />
        <link rel="stylesheet" type="text/css" href="css/hoverdemo.css">
		<link rel="stylesheet" href="/css/strategyDetails.css" />
		<link rel="stylesheet" href="/js/plugins/dialog2/dialog.css" />
		<script src="/js/plugins/jrender/jrender.min.js"></script>
        <script src="/js/plugins/dialog2/dialog.min.js"></script>
		<script src="/js/common.js"></script>
		<style>
			.button2:hover {
				box-shadow: 0 12px 16px 0 rgba(0,0,0,0.24), 0 17px 50px 0 rgba(0,0,0,0.19);
			}
		</style>

		<script>
			$(function () {
                //获取参数
                var params = getParams();

                //获取当前用户的id
                var user = JSON.parse(sessionStorage.getItem("user"));

                //发送请求获取对应文章信息(根据文章id查找)
                $.get("/dailyPaper/" + params.id, function (data) {
                    console.log(data);
                    //填充文章信息
                    $(".detail").renderValues(data);
                });

                //通过用户id查询对应的点赞和收藏信息
                $.get('/dailyPaper/Collect/'+user.id,function (data) {
                    $.each(data,function (index,ele) {
                        //console.log(ele+"collect");
                        if(ele==params.id){
                            state=1;
                            $("#collectBtn").removeClass("fa-star-o").addClass("fa-star")
                            $("#collectBtn").css("color","yellow");
                        }
                    })
                })

                $.get('/dailyPaper/like/'+user.id,function (data) {
                    $.each(data,function (index,ele) {
                        //判断收藏的日报id是否和当前日报id一致
                        //console.log(ele+"like");
                        if(ele==params.id){
                            //回显
                            type=1;
                            $("#likeBtn").removeClass("fa-thumbs-o-up").addClass("fa-thumbs-up")
                            $("#likeBtn").css("color","red");
                        }
                    })
                })


                //点赞
                var type=0;
                $("#likeBtn").click(function () {
                    if(user!=null){
                        if(type==0){
                            type=1;
                            $(this).removeClass("fa-thumbs-o-up").addClass("fa-thumbs-up")
                            $(this).css("color","red");
                            //发送请求维护关系
                            $.post("/dailyPaper/addLike/"+user.id+""+"/"+params.id,function (data) {

                            })
                        }else{
                            $(this).css("color","black");
                            $(this).removeClass("fa-thumbs-up").addClass("fa-thumbs-o-up")
                            type=0;
                            //发送请求解除关系
                            $.ajax({
                                type:"delete",
                                url:"/dailyPaper/removeLike/"+user.id+"/"+params.id
                            })
                        }
                    }else{
                        $(document).dialog({
                            titleText: "温馨提示",
                            content: "请先登录再进行操作",
                            //onClosed弹框关闭之后执行
                            onClosed:function () {
                                //没有结果就返回上一级页面
                                window.location.href="/login.html"
                            }
                        });
                    }
                })





                //给收藏按钮绑定点击事件
                var state=0;
                $("#collectBtn").click(function () {
                    //判断示是否为登录状态
                    if(user!=null){
                        if(state==0){
                            state=1;
                            $(this).removeClass("fa-star-o").addClass("fa-star")
                            $(this).css("color","yellow");
                            //发送请求维护关系
                            $.post("/dailyPaper/addCollect/"+user.id+""+"/"+params.id,function (data) {

                            })
                        }else{
                            $(this).css("color","black");
                            $(this).removeClass("fa-star").addClass("fa-star-o")
                            state=0;
                            //发送请求解除关系
                            $.ajax({
                                type:"delete",
                                url:"/dailyPaper/removeCollect/"+user.id+"/"+params.id
                            })
                        }
                    }else{
                        $(document).dialog({
                            titleText: "温馨提示",
                            content: "请先登录再进行操作",
                            //onClosed弹框关闭之后执行
                            onClosed:function () {
                                //没有结果就返回上一级页面
                                window.location.href="/login.html"
                            }
                        });
                    }
                })
            });
		</script>
	</head>

	<body>

	<div class=" nav-search">
		<a href="javascript:history.go(-1);">
			<span><i class="fa fa-chevron-left"></i></span>
		</a>
	</div>
	<hr>

	<div class="container detail">
		<h4 class="title"><strong render-html="title"></strong></h4>
		<img class="head-img" render-src="coverUrl">
		<div class="author"><span ></span></div>
		<div class="content" render-html="content">
		</div>
	</div>
    <br/>
    <br/>
	<!--<button class="btn button2" style="background-color: #00bbd3">按钮</button>-->
    <div class="container d-flex footer" align="center" style="background-color: #c5d9e8">
        <!--点赞按钮-->
        <div class="p-2  flex-fill">
            <i class="fa-2x fa fa-thumbs-o-up"  id="likeBtn" > </i>
        </div>
        <!--收藏按钮-->
        <div class="p-2  flex-fill star">
            <i class="fa-2x fa fa-star-o" id="collectBtn"> </i>
        </div>
    </div>


	</body>

</html>